﻿using System;
using BGShell.PowerShell.Controls;

namespace BGShell.PowerShell
{
    public sealed class PowerShellAddIn : BGShellAddIn
    {
        private ConsoleTabPage _bgpage;

        protected override Type[] GetTabTypes()
        {
            return new Type[] { typeof(ConsoleTabPage) };
        }

        protected override void OnApplicationStartup(BGShellApplication application)
        {
            if (application.Arguments.IsBackground)
            {
                _bgpage = new ConsoleTabPage()
                {
                    ConsoleControl =
                    {
                        IsBackground = true,
                    },
                };

                _bgpage.CreateControl();
                _bgpage.OpenAsync();

                application.AddNotifyIconCommand(Resources.NotifyOpenBGRunspace, OnOpenBackgroundRunspace);
            }
        }

        private void OnOpenBackgroundRunspace(Object sender, EventArgs e)
        {
            BGShellApplication.Current.Windows.BackgroundWindow.OpenTab(_bgpage);
            BGShellApplication.Current.ActivateBackgroundWindow();
        }
    }
}
